﻿@model AesApplication.Models.JobsViewModel
@using AesApplication.Models;
@{
    ViewBag.Title = "Jobs";
}
<script type="text/javascript">
    function selectStore() {

        var stores = document.getElementById('stores');
        var selectedStore = stores.options[stores.selectedIndex];
        if (selectedStore.value != "nothing") {
            window.location = "/Home/Jobs/"+selectedStore.value;
        }
    }
</script>

<h2>Job Openings at @Model.Selected.Name</h2>

@foreach (var dept in Model.Selected.Departments)
{
    <h3>@dept.Name</h3>
    if (dept.Jobs.Where(x=> (x.Status == JobStatus.Active) && (x.StartDate <= System.DateTime.Now) && (x.EndDate >= System.DateTime.Now)).Count() > 0)
    {
        <ul>
        @foreach (Job job in dept.Jobs.Where(x => (x.Status == JobStatus.Active) && (x.StartDate <= System.DateTime.Now) && (x.EndDate >= System.DateTime.Now)))
        {
            <li>
            <h4>@Html.ActionLink(job.Title, "Job", new { id = job.ID })</h4>
            <span>@job.ShortDescription</span>
            </li>
        }
        </ul>
    }
    else
    {
        <i>There are no job openings in this department.</i>
    }
    
}

<br />

<form>
    <select id='stores' onchange="selectStore()">
        <option value="nothing">Choose a different store</option>
        @foreach (var store in Model.Stores)
        {
            <option value=@store.ID>@store.Name</option>
        }
    </select>
</form>